package com.hmyd.hmyd_android.adapter;

import java.util.List;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.dto.RedemptionHistory;
import com.hmyd.hmyd_android.utils.Utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 赎回记录数据适配
 * @author wangk
 */
public class BillRedeemHistoryAdapter extends BaseAdapter {

	private Context mContext;
	private List<RedemptionHistory> data;
	private LayoutInflater mInflater;

	public BillRedeemHistoryAdapter(Context context, List<RedemptionHistory> data){
		super();
		
		this.mContext = context;
		this.data = data;
		mInflater=LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		return data != null ? data.size() : 0;
	}

	@Override
	public RedemptionHistory getItem(int position) {
		return data != null ? data.get(position) : null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(data==null || data.get(position)==null){
			return convertView;
		}
		
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.view_redeem_history_list, null);
			holder = new ViewHolder();
			
			holder.redeem_amount = (TextView)convertView.findViewById(R.id.redeem_amount);
			holder.redeem_status = (TextView)convertView.findViewById(R.id.redeem_status);
			holder.redeem_time = (TextView)convertView.findViewById(R.id.redeem_time);
			holder.line = convertView.findViewById(R.id.line1);
			
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		
		RedemptionHistory redemptionHistory = getItem(position);
		if(redemptionHistory!=null){
			
			holder.redeem_amount.setText(Utils.amountConversionFormat(redemptionHistory.amountAll));
			
			if("赎回成功".equals(redemptionHistory.status) || "赎回中".equals(redemptionHistory.status)){
				holder.redeem_status.setTextColor(mContext.getResources().getColor(R.color.home_shf_text));
			}else if("赎回失败".equals(redemptionHistory.status)){
				holder.redeem_status.setTextColor(mContext.getResources().getColor(R.color.home_rate_color));
			}else{
				holder.redeem_status.setTextColor(mContext.getResources().getColor(R.color.investment_item_title_text));
			}
			
			holder.redeem_status.setText(redemptionHistory.status);
			
			holder.redeem_time.setText(Utils.getDateString(redemptionHistory.createdTime));
			
//			if(data.size()==(position+1)){
//				holder.line.setVisibility(View.INVISIBLE);
//			}else{
//				holder.line.setVisibility(View.VISIBLE);
//			}
			
		}
		
		return convertView;
	}
	
	class ViewHolder{
		TextView redeem_amount;
		TextView redeem_status;
		TextView redeem_time;
		View line;
	}

}
